package com.hxzy.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hxzy.common.vo.R;
import com.hxzy.controller.BaseController;
import com.hxzy.dto.SysDictDataSearchDTO;
import com.hxzy.entity.SysDictData;
import com.hxzy.service.SysDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "字典明细API")
@RestController
@RequestMapping(value = "/api/dictdata")
public class SysDictDataController extends BaseController {

    @Autowired
    private SysDictDataService sysDictDataService;

    /**
     * 根据类型查询值
     * @param dictType
     * @return
     */
    @ApiOperation(value = "根据字典类型查询值")
    @GetMapping(value = "/dicttype/{name}")
    public R  findByDictType(@PathVariable(value = "name") String dictType){
        List<SysDictData> byDictType = this.sysDictDataService.findByDictType(dictType);
        return R.okHasData(byDictType);
    }

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @ApiOperation(value = "分页查询")
    @GetMapping(value = "/data")
    public R  findByDictTypePage(@Valid SysDictDataSearchDTO dto){
        IPage<SysDictData> page = this.sysDictDataService.findByDictTypePage(dto);
        return  super.ipageToPage(page);
    }
}
